/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commands;

import cmdhelpers.TranslateHelper;
import context.ContextEvolutif;
import context.IContext;

import java.io.PrintStream;
import java.util.Locale;

/**
 *
 * eCOM - Adopte un Presta - Mars-Avril 2013
 * @author Kheira, Jef, William, Tuan-Long
 */
public class LanguageCommand extends CommandAbstract implements ICommandContextuelle 
{
    	private final TranslateHelper translateHelper;
	private IContext context;
        
	public LanguageCommand() 
        {
		this(ContextEvolutif.contextE);
	}

	public LanguageCommand(IContext context) 
        {
		this.context = context;
		this.translateHelper = new TranslateHelper(this);
	}

	@Override
	public String getName() {
		return "language";
	}

	@Override
	public String getUsage() 
        {
		return translateHelper.translate("usage");
	}

	@Override
	public String getShortDescription() 
        {
		return translateHelper.translate("desc");
	}


	@Override
	public IContext getContext() 
        {
		return context;
	}

	@Override
	public void setContext(IContext context) 
        {
		this.context = context;
	}

	@Override
	protected void execute(PrintStream out, PrintStream err) {
		if (dataArguments.isEmpty()) {
			out.println(translateHelper.getLocale().getDisplayLanguage());
		} else {
			Locale newLocale = new Locale(dataArguments.getFirst());
			this.translateHelper.setLocale(newLocale);
		}
	}
}
